import { defineConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
function pathResolve(dir) {
  return resolve(__dirname, '.', dir)
}

export default defineConfig({
  base: '',
  plugins: [vue(),viteCommonjs()],
  css:{preprocessorOptions:{
    scss:{
      additionalData:`@import "./src/styles/base.scss";` //此处为全局scss文件
    }
    }},
  resolve: {
    alias: {
      '@': pathResolve('src'),
    },

  },
  optimizeDeps: {
    include: ['axios'],
  },
  build: {
    target: 'modules',
    outDir: 'dist',
    assetsDir: 'assets',
    minify: 'terser', // 混淆器
  },
  server: {
    open: true,
    port: '8000',
    hmr: { overlay: false },
    proxy: {
      ['/manager']: { //自动化平台golang
        target: 'http://localhost:9999/',
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^'), ''),
      },
      ['/api/v1']: { //自动化平台golang
        target: 'http://localhost:9999/',
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^'), ''),
      },
      ['/api/v2']: { // 自动化平台python
        target: 'http://localhost:8081/',
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^'), ''),
      },
      ['ws']: { //websocket 平台
        target: 'ws://localhost:8082/',
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp('^'), ''),
      },
    },
  },
  define: {
    'process.env': {},
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  },
})
